package cn.kattomy.shop.adminuser.action;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.kattomy.shop.adminuser.service.AdminUserService;
import cn.kattomy.shop.adminuser.vo.AdminUser;

public class AdminUserAction extends ActionSupport implements ModelDriven<AdminUser>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//模型驱动使用的对象
	private AdminUser adminUser = new AdminUser();
	
	@Override
	public AdminUser getModel() {
		return adminUser;
	}
	
	//注入 Service
	private AdminUserService adminUserService;

	public void setAdminUserService(AdminUserService adminUserService) {
		this.adminUserService = adminUserService;
	}
	
	/**
	 * 后台登录的方法
	 */
	public String login(){
		//调用 Service 完成登录：
		AdminUser existAdminUser = adminUserService.login(adminUser);
		if (existAdminUser == null) {
			//登录失败
			this.addActionError("用户名或密码错误！");
			return "loginFail";
		}else {
			//登录成功
			ServletActionContext.getRequest().getSession().setAttribute("existAdminUser", existAdminUser);
			 return "loginSuccess";
		}
		
	}
	
	public String home(){
		return "home";
	}
	
	public String calendar(){
		return "calendar";
	}
	
	public String chat(){
		return "chat";
	}
	
}
